package com.guet.game.Item;

import com.guet.game.World;
import com.guet.game.airplanes.dao.FlyingObj;
import com.guet.game.airplanes.dao.Gift;
import com.guet.game.utils.Images;

import java.awt.image.BufferedImage;

public class Item extends FlyingObj implements Gift {

    int Xspeed;
    int Yspeed;

    int itemType;

    int lifeTime;

    public Item(int x,int y) {
        super(16, 16,x,y);


        int i = (int)(Math.random()*2);
        if(i==0){
            Xspeed = 2;
        }else{
            Xspeed = -2;

        }
        Yspeed = 2;
        itemType = (int) (Math.random() * 2);
        lifeTime = 10;
    }

    @Override
    public BufferedImage getImage() {
        if (state == LIFT) {
            if(itemType==0)
                return Images.healItems;
            if(itemType==1)
                return Images.damageItems;
        }
        return null;
    }

    @Override
    public void move() {
        if (x <=0 || x >= World.WIDTH - this.width) {
            Xspeed = -Xspeed;
        }

        if(y<=0||y>=World.HEIGHT - this.height*2){
            Yspeed = -Yspeed;
        }

        y += Yspeed;
        x += Xspeed;

    }

    @Override
    public int getAwardType() {
        return itemType;
    }

    @Override
    public Item DropGift(int type) {
        return null;
    }

    public int getLifeTime(){
        return lifeTime;
    }
}
